#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

get_char() {
  SAVEDSTTY=$(stty -g)
  stty -echo
  stty cbreak
  dd if=/dev/tty bs=1 count=1 2>/dev/null
  stty -raw
  stty echo
  stty $SAVEDSTTY
}

char=$(get_char)
# 判断是否为root用户
[[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] This script must be run as root!" && exit 1

# 判断JDK源文件是否下载过
if [ ! -f "./jdk-8u202-linux-x64.tar.gz" ]; then
  wget https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz
fi

# 解压JDK到指定文件夹
mkdir -p /usr/local/java && tar -zxvf jdk-8u202-linux-x64.tar.gz -C /usr/local/java

# 添加JDK到环境变量
chmod 700 /etc/profile
echo '#Java Env' >>/etc/profile
echo 'export JAVA_HOME=/usr/local/java/jdk1.8.0_202' >>/etc/profile
echo 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >>/etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >>/etc/profile
source /etc/profile

